﻿@model IEnumerable<tcms.Models.UserModel>
@{
    ViewBag.Title = "Users";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>用户列表</h2>
<table class="flexme">
    <thead>
        <tr>
            <th>@Html.DisplayNameFor(model => model.Name) </th>
            <th>@Html.DisplayNameFor(model => model.Role) </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>@Html.DisplayFor(modelItem => item.Name) </td>
                <td>@Html.DisplayFor(modelItem => item.Role) </td>
                @if (HttpContext.Current.User.Identity.Name == item.Name)
                {
                    <td class="disabled"><span>删除</span></td>
                }
                else
                {
                    <td>@Html.ActionLink("删除", "Delete", new { id = item.Id }, new { @class = "delete" }) </td>
                }
            </tr>
        }
    </tbody>
</table>
@section inlinestyle {
td.disabled { color: #ccc; }
}
@section links {
    <link rel="stylesheet" href="~/Content/bootstrap/css/bootstrap.css" />
}
@section scripts {
    @Scripts.Render("~/bundles/js/jquery")
    <script type="text/javascript">
        $(function () {
            $('.flexme a.delete').click(function (event) {
                event.preventDefault();

                var link = $(this);
                if (confirm("Are you sure to remove this user?")) {
                    $.post($(this).attr("href")).fail(function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                    }).done(function (data) {
                        link.closest('tr').remove();
                        alert(data);
                    });
                }
            });
        });

    </script>
}
